package com.wxy.ej.flow.modules.act.listen;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;


/**
 * 每个人完成任务，都会执行一下。
 */
@Slf4j
@Component("subTaskCompleteListener")
@Scope("prototype")
public class SubTaskCompleteListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution delegateExecution) {
        log.info("---->act listener: SubTaskCompleteListener");

        System.out.println("======= 子流程完成 subTaskCompleteListener ======");
        System.out.println("EventName:" + delegateExecution.getEventName());
        System.out.println("ProcessDefinitionId:" + delegateExecution.getProcessDefinitionId());
        System.out.println("ProcessInstanceId:" + delegateExecution.getProcessInstanceId());
/*
        // 子流程，部门子任务，只有一个部门信息
        Map companyMap = (Map)delegateExecution.getVariableLocal("companyMap");
        System.out.println("companyMap: "+companyMap);
        List<Map> companyList = new ArrayList<>();
        companyList.add(companyMap);
        // 完成部门子任务，和部门下员工任务
        cityTaskAutoService.completeBizTaskSon(companyList);


        // 流程执行日志
        FlowElement flowElement = delegateExecution.getCurrentFlowElement();
        // ${companyId}
        String doc = ExpressionUtils.parse(flowElement.getDocumentation(), delegateExecution);


        CtcTaskLogBizDto taskLogDto = new CtcTaskLogBizDto();
        taskLogDto.setCtcTaskId(Long.parseLong(delegateExecution.getProcessInstanceBusinessKey()));
        taskLogDto.setFlowElementId(flowElement.getId());
        taskLogDto.setFlowElementName(flowElement.getName());
        taskLogDto.setFlowElementDoc(doc);
        taskLogDto.setCreatedate(DateTool.currentDate("yyyy-MM-dd HH:mm:ss.SSS"));
        StringBuilder sb = new StringBuilder();
        sb.append("子流程完成； 修改业务表状态：完成部门子任务，和部门下员工任务");
        taskLogDto.setDescription(sb.toString());
        ctcTaskLogBizService.create(taskLogDto);*/
    }
}
